From: Eric Curtin Date: Tue, 22 Aug 2023 12:11:30 +0000 (+0100) Subject: prepare-root: Changes made to find_proc_cmdline_key X-Git-Tag: archive/raspbian/2023.7-3+rpi1~1^2~9^2^2~12^2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=6e9e50d87c8869882de920c096125af36218ae06;p=ostree.git prepare-root: Changes made to find_proc_cmdline_key Used strspn based on feedback from similar function. --- diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 1c15fe90..eb79efdf 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -87,29 +87,26 @@ cleanup_free (void *p) static inline char * find_proc_cmdline_key (const char *cmdline, const char *key) { - char *ret = NULL; - size_t key_len = strlen (key); - - const char *iter = cmdline; - while (iter != NULL) + const size_t key_len = strlen (key); + for (const char *iter = cmdline; iter;) { const char *next = strchr (iter, ' '); - const char *next_nonspc = next; - while (next_nonspc && *next_nonspc == ' ') - next_nonspc += 1; if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=') { const char *start = iter + key_len + 1; if (next) - ret = strndup (start, next - start); - else - ret = strdup (start); - break; + return strndup (start, next - start); + + return strdup (start); } - iter = next_nonspc; + + if (next) + next += strspn (next, " "); + + iter = next; } - return ret; + return NULL; } /* This is an API for other projects to determine whether or not the